home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / MPW / gzip 1.2.2 / primos / alloca.pma next >
Encoding:
Text File  |  1993-06-22  |  1.5 KB  |  46 lines  |  [TEXT/MPS ]

  1. *
  2. * ALLOCA.PMA                                      Stack heap storage allocator.
  3. *
  4. * Date      Programmer     History
  5. * --------- -------------- --------------------------------------------------
  6. * 880805    P. Eriksson    Initial coding.
  7. *
  8.  
  9.  
  10.          SEGR
  11.          SYML
  12.          RLIT
  13.  
  14.          ENT G$ALLOCA,ECB$$
  15.  
  16. P$ALLOCA EQU *
  17.          L 2,XB%+0            - Fetch 'size' argument
  18.          BRLE 2,FAIL          - Terminate if 'size' <= 0
  19.          IR1 2                - Compensate for odd bytes
  20.          SR1 2                - Convert to number of shorts
  21.          BHNE 2,FAIL          - Fail if high word != 0
  22.          IRH 2                - Put length into halfword
  23.          CH% 2,=65530         - Compare with maximum limit
  24.          BMGT FAIL            - Fail if block too big
  25.          IRH 2                - Put length into fullword
  26.          L 1,2                - Save length for later usage
  27.          STEX 2               - Allocate stack storage
  28.  
  29.          L 3,2                - Save block pointer for later
  30.  
  31. ZNEXT    ZMH R2%              - Clear halfword
  32.          IR1 2                - Point at next
  33.          DR1 1                - Decrement length
  34.          BRGT 1,ZNEXT         - Loop until length == 0
  35.  
  36.          L 2,3                - Get block pointer back
  37.          JMP R0%              - Return to caller
  38.  
  39. FAIL     CR 2                 - Put a NULL pointer into R2
  40.          JMP R0%              - Return to caller
  41.  
  42.          LINK
  43. ECB$$    ECB P$ALLOCA,,,-1
  44.  
  45.          END
  46.